package fr.p10.miage.gestionnote.model;
// Generated 20 mai 2014 15:44:05 by Hibernate Tools 3.2.1.GA


import fr.p10.miage.gestionnote.modelservice.ControleServices;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Controle implements java.io.Serializable 
{

     public static final int DST = 1;
     public static final int PARTIEL = 2;
     public static final int RATTRAPAGE = 3;

     private int idEtudiant;
     private int idP;
     private int idEc;
     private int idcontrole;
     private String label;
     private float coefficient;
     private boolean publier;
     private int type;
     private int echelle;
     private List<Note> notes = new ArrayList<Note>();
    
    public Controle(int idcontrole,int idP, int idEc, String label, float coefficient,int echelle, boolean publier, int type,int idEtudiant) {
        this.idcontrole = idcontrole;
        this.idP =idP;
        this.idEc =idEc;
        this.label = label;
        this.coefficient = coefficient;
        this.publier = publier;
        this.type = type;
        this.echelle = echelle;
        this.idEtudiant = idEtudiant;
        this.setNotesEtudiant();
    }
    
    public Controle(int idcontrole,int idP, int idEc, String label, float coefficient,int echelle, boolean publier, int type) {
        this.idcontrole = idcontrole;
        this.idP =idP;
        this.idEc =idEc;
        this.label = label;
        this.coefficient = coefficient;
        this.publier = publier;
        this.type = type;
        this.echelle = echelle;
        this.idEtudiant = idEtudiant;
        // Revoir
        this.setNotesIntervenant();
    }   
    public String getTypeControleLabel(int type)
    {
        String label="";
        switch(type)
        {
            case Controle.DST:
                label = "Contrôle";
                break;
            case Controle.PARTIEL:
                label = "Partiel";
                break;
            case Controle.RATTRAPAGE:
                label = "Rattrapage";
                break;    
        }
        return label;
    }
    
    public Note getNoteByEtudiantId(int idEtudiant)
    {
        Note noteEtudiant =null;
         try {
             //Requete Sql
             noteEtudiant=ControleServices.getNoteByEtudiantId(this.idcontrole,idEtudiant);
         } catch (SQLException ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         }
        return noteEtudiant;
    }
    
    public float calculNoteMoyenneControle()
    {
        float moy=0;
        
         try {
             moy =ControleServices.calculNoteMoyenneControle(idcontrole);
             
         } catch (SQLException ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         }
         
         return moy;
    }
    
    public float calculNoteBasseControle()
    {
        float min=0;
        
         try {
             min =ControleServices.calculNoteBasseControle(idcontrole);
             
         } catch (SQLException ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         }
         
         return min;
    }
    public int calculNbEtudiantNote(){
        int nbEtudiantNote=0;
         try {
             nbEtudiantNote =ControleServices.calculNbEtudiantNote(idcontrole);
             
         } catch (SQLException ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         }
         
         return nbEtudiantNote;
    }
    
     public int calculNbEtudiantDispense(){
        int nbEtudiantDispense=0;
         try {
             nbEtudiantDispense =ControleServices.calculNbEtudiantDispense(idcontrole);
             
         } catch (SQLException ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         }
         
         return nbEtudiantDispense;
    }
    public float calculNoteHauteControle()
    {
        float max=0;
        
         try {
             max =ControleServices.calculNoteHauteControle(idcontrole);
             
         } catch (SQLException ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         }
         
         return max;
    }
    
    public int calculNbEtudiantClasse()
    {
        int nbEtudiant=0;
        
         try {
             nbEtudiant =ControleServices.calculNbEtudiantClasse(idcontrole);
             
         } catch (SQLException ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         } catch (Exception ex) {
             Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
         }
         
         return nbEtudiant;
    }

    public int getEchelle() {
        return echelle;
    }

    public void setEchelle(int echelle) {
        this.echelle = echelle;
    }
    
    public int getIdP() {
        return idP;
    }

    public void setIdP(int idP) {
        this.idP = idP;
    }

    public int getIdEc() {
        return idEc;
    }

    public void setIdEc(int idEc) {
        this.idEc = idEc;
    }   
    public float getCoefficient() {
        return coefficient;
    }

    public void setCoefficient(float coefficient) {
        this.coefficient = coefficient;
    }

    public boolean isPublier() {
        return publier;
    }

    public void setPublier(boolean publier) {
        this.publier = publier;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

     
    public List<Note> getNotes() 
    {
        
        return this.notes;
    }

    // Revoir
    public void setNotesEtudiant() 
    {

            try {
                this.notes = ControleServices.getNotes(idcontrole,idEtudiant);
            } catch (SQLException ex) {
                Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

    public void setNotesIntervenant() 
    {
         try {
                this.notes = ControleServices.getNotes(idcontrole);
            } catch (SQLException ex) {
                Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
            }
    }    
    public int getIdcontrole() {
        return idcontrole;
    }

    public void setIdcontrole(int idcontrole) {
        this.idcontrole = idcontrole;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }   

}


